package com.example.providertets;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private String newId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button queryData =(Button) findViewById(R.id.query_data);
        queryData.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
//                查询数据
                Uri uri = Uri.parse("content://com.example.test99.provider/contacts");
                Cursor cursor = getContentResolver().query(uri,null,null,null,null);
                if(cursor != null){
                    while(cursor.moveToNext()) {
                        @SuppressLint("Range") String name = cursor.getString(cursor.getColumnIndex("name"));
                        @SuppressLint("Range") Integer number = cursor.getInt(cursor.getColumnIndex("number"));
                        @SuppressLint("Range") String gender = cursor.getString(cursor.getColumnIndex("gender"));

                        Log.d("MainActivity", "contact name is" + name);
                        Log.d("MainActivity", "contact number is" + number);
                        Log.d("MainActivity", "contact gender is" + gender);

                    }
                    cursor.close();
                }
            }
        });
    }
}